<?php


namespace App\Common\Lib;


class MrpCode
{
    public static function createCode()
    {
        $user_id = mt_rand(1,999999);
        $source_string = str_shuffle("E5FCDG3HQA4B1NOPIJ2RSTUV67MWX89KLYZ");

        $num = $user_id;
        $code = '';
        while ( $num > 0) {
            $mod = $num % 35;
            $num = ($num - $mod) / 35;
            $code = $source_string[$mod].$code;
        }
        if(empty($code[3]))
            $code = str_pad($code,4,'0',STR_PAD_LEFT);
        return $code;
    }
}
